package TUILayer;//makes this class a part of the TUILayer package

import java.util.Scanner;

import ControlLayer.*;//The TUILayer needs to know the ControlLayer

public class MainMenuUI {
    //the reference to the ControlLayer
    private AddressBookUI adrUI;//references to other UI objects
    private DvdUI dvdUI;

    public MainMenuUI() {

    }

    public void mainMenuStart() {
        boolean exit = false;

        while (!exit) //! means while exit not is true (that is: false)
        {
            int choice = writeMainMenu();

            switch (choice) {
                case 1:
                    startAddressBook();

                    break;
                case 2:
                    startDvd();
                    break;
                case 3:
                    // TODO - Crud til TODO.
                    // Simon
                    break;
                case 4:
                    // (4) Close
                    exit = true;
                    break;
                default:
                    System.out.println("You must enter a valid choice.");

                    break;
            }

        }//end while
    }//end start

    private int writeMainMenu() {
        // creates a keyboard object to read input
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\f *** MainMenu ***");
        System.out.println(" (1) AddressBook");
        System.out.println(" (2) DVDs");
        System.out.println(" (3) Loan");
        System.out.println(" (4) Close");
        System.out.print("\n Make your choice: ");

        int choice = 0;
        try {
            choice = keyboard.nextInt();
        }
        catch (Exception e) {
            System.out.println("You must enter a number -  try again");
            String input = keyboard.nextLine();
        }
        return choice;
    }

    private void startAddressBook() {
        adrUI = new AddressBookUI();
        adrUI.start();
    }

    private void startDvd() {
        dvdUI = new DvdUI();
        dvdUI.start(new DVDCtr());
    }

    private void writeEnd()

    {
        System.out.println(" The System is shutting down ");
    }
}
